function swapArray<T extends any[]>(arr: T, index1: number, index2: number) {
  arr[index1] = arr.splice(index2, 1, arr[index1])[0];
  return arr;
}

export function moveUp<T extends any[]>(arr: T, index: number) {
  if (index === 0) {
    return arr;
  }
  return swapArray(arr, index, index - 1);
}

export function moveDown<T extends any[]>(arr: T, index: number) {
  if (index === arr.length - 1) {
    return arr;
  }
  return swapArray(arr, index, index + 1);
}
